var app = getApp()
var httpTool = require('../../utils/network.js')
Page({
  data: {
    array: [],
    provinceId: '',   //省份
    provinceName: '',   //省份
    cityId: '',     //市
    cityName: '',     //市
    countryId: '',   //区
    countryName: ''   //区
  },
  onLoad: function (options) {
    // 生命周期函数--监听页面加载
    this.getListData()
  },
  onReady: function () {
    // 生命周期函数--监听页面初次渲染完成

  },
  onShow: function () {
    // 生命周期函数--监听页面显示

  },
  onHide: function () {
    // 生命周期函数--监听页面隐藏

  },
  onUnload: function () {
    // 生命周期函数--监听页面卸载

  },
  onPullDownRefresh: function () {
    // 页面相关事件处理函数--监听用户下拉动作

  },
  onReachBottom: function () {
    // 页面上拉触底事件的处理函数

  },
  selectModelClick: function (event) {

    var model = event.currentTarget.dataset.model
    console.log(model)
    if (this.data.provinceId.length == 0) {
      this.setData({
        provinceId: model.id,
        provinceName: model.keyName,
      })
      this.getCityListData(model.id)
      wx.setNavigationBarTitle({
        title: model.keyName,
      })
    } else if (this.data.cityId.length == 0) {

      this.setData({
        cityId: model.id,
        cityName: model.keyName,
      })
      this.getCityListData(model.id)
      wx.setNavigationBarTitle({
        title: model.keyName,
      })
    } else {
      this.setData({
        countryId: model.id,
        countryName: model.keyName,
      })
      app.cityData.provinceId = this.data.provinceId
      app.cityData.provinceName = this.data.provinceName
      app.cityData.cityId = this.data.cityId
      app.cityData.cityName = this.data.cityName
      app.cityData.countryId = this.data.countryId
      app.cityData.countryName = this.data.countryName

      wx.navigateBack({
        delta: 1
      })
    }


  },
  getListData: function () {
    var that = this
    var url = app.data.httpUrl + 'v1/region/listAll'
    var param = {parentId:1000}
    console.log(param)
    httpTool.sendRequest(url, param, '加载中...', function (res) {
      that.setData({
        array: res.list
      })
    }, function (error) {

    });
  },
  getCityListData: function (postId) {
    var that = this
    var url = app.data.httpUrl + 'v1/region/listAll'
    var param = { parentId: postId }
    console.log(param)
    httpTool.sendRequest(url, param, '加载中...', function (res) {
      that.setData({
        array: res.list
      })
    }, function (error) {

    });
   
  }
})